﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using Avatar.ResumeService;
using Avatar.Person;
using Avatar.Common;
using Avatar.Company;

public partial class PersonFavorites : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Membership.GetUser() != null)
            {
                var _jobs = FavoriteManager.GetFavorites(Membership.GetUser().UserName);
                ListView1.DataSource = _jobs;
                ListView1.DataBind();
            }
        }
    }
    protected void btn_Apply_Click(object sender, EventArgs e)
    {
            try
            {
                Button _btn = sender as Button;
                Guid _jobID = string.IsNullOrEmpty(_btn.CommandArgument) ? Guid.Empty : new Guid(_btn.CommandArgument);
                JobApplicationRecordManager.apply(Membership.GetUser().UserName, _jobID);

                Helper.ShowMassage("申请成功！", Request.Url.ToString());
            }
            catch (Exception _e)
            {
                Helper.ShowMassage(_e.Message, Request.Url.ToString());
            }
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        try
        {
            Button _btn = sender as Button;
            int _id = string.IsNullOrEmpty(_btn.CommandArgument) ? 0 : Convert.ToInt32(_btn.CommandArgument);

            FavoriteManager.DeleteAFavorite(_id);
            Response.Redirect(Request.Url.ToString());
        }
        catch (Exception _e)
        {
            lbl_Error.Text = _e.Message;
        }
    }
    protected string UpdateButtonTextValue(Guid _jobID)
    {
        string _textValue = string.Empty;

        _textValue=JobManager.AmIApplyedThisJob(_jobID,Membership.GetUser().UserName) ? "已申请" : "申请";

        return _textValue;
    }
    protected bool UpdateButtonEnable(Guid _jobID)
    {
        return JobManager.IsTheJobExpired(_jobID) || JobManager.AmIApplyedThisJob(_jobID, Membership.GetUser().UserName) ? false : true;
    }
}
